package dao

import (
	"zg3zk3/inits"
	"zg3zk3/model"
)

func CreateMessage(formUserId int, toUserId int, context string) bool {
	var max1 = formUserId
	var min1 = toUserId
	if formUserId < toUserId {
		max1 = toUserId
		min1 = formUserId
	}

	result := &model.Message{
		FormUserId: formUserId,
		ToUserId:   toUserId,
		RoomId:     min1*10000 + max1,
		Context:    context,
	}
	if inits.DB.Create(&result).Error != nil {
		return false
	}
	return true
}
